var popstate_flag = true;
if( window.history.replaceState != undefined){
    if(window.history.state && window.history.state.url){
       // if(window.history.state.url != location.href)
        popstate_flag = false;
    } else {
        var json ={time:new Date().getTime(),url:location.href};
        window.history.replaceState(json,"",location.href);
    }
}


function doUserLogs(logBean,type){

    if (arguments.length == 0)
        return;

    if (!popstate_flag)
        return;

    var userEventConfig = {};
    userEventConfig.eventType = "WAP";
    userEventConfig.url = "http://wap.js.10086.cn/bigdata/v3/c_afx";
    userEventConfig.method = "POST";
    userEventConfig.eventName = "WAPBUSI";
    userEventConfig.triggerTypes = ["now"];
    
    var paramers = {};

    paramers.moduleID = logBean.moduleID||"";
    paramers.activityID = logBean.activityID||"";
    paramers.targetUser = logBean.targetUser||"";
    paramers.date = dateFormater(new Date(), 'yyyyMMdd');
    paramers.time = dateFormater(new Date(), 'HHmmss');
    paramers.procType = logBean.procType||"";
    paramers.prizeID = logBean.prizeID||"";
    paramers.pageVID = $$XWBD_API.getPageInfo("pageVID")||"";
    paramers.pageCode = $$XWBD_API.getPageInfo("pageCode")||"";
    paramers.areaVID = $$XWBD_API.getPageInfo("areaVID")||"";
    paramers.areaCode = $$XWBD_API.getPageInfo("areaCode")||"";
    paramers.sourceType = $$XWBD_API.getPageInfo("sourceType")||"";
    paramers.sourcePointName = $$XWBD_API.getPageInfo("sourcePointName")||"";
    paramers.userType = "1";
    paramers.userLabel = logBean.userLabel||"";
    paramers.userGroup = logBean.userGroup||"";

    userEventConfig.paramers = paramers;

    $$XWBD_API.userEvents([userEventConfig]);
}

function preZeroFill (num, size) {
    if (num >= Math.pow(10, size)) { // 如果num本身位数不小于size位
        return num.toString();
    } else {
        var _str = Array(size + 1).join('0') + num;
        return _str.slice(_str.length - size);
    }
};

function dateFormater (date, pattern) {
    if (!date) {
        return "";
    }
    var month = date.getMonth() + 1;
    var nowday = date.getDate();
    var hh = date.getHours();
    var mm = date.getMinutes();
    var ss = date.getSeconds();
    var ms = date.getMilliseconds();
    return pattern.replace("yyyy", date.getFullYear()).replace("MM", preZeroFill(month, 2)).replace("dd", preZeroFill(nowday, 2)).replace("HH", preZeroFill(hh, 2)).replace("mm", preZeroFill(mm, 2)).replace("ss", preZeroFill(ss, 2)).replace("SSS", preZeroFill(ms, 3));
}